<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册页面</title>
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/blog_sign.css">
    <script src="js/jquery.min.js"></script>
</head>
<body>
    <div class="nav">
        <!--头像-->
        <img src="css/cat.jpg" alt="">
        <span>博客系统</span>
        <!--使用空白元素，进行占位-->
        <div class="spaner">
            <span> </span>
        </div>
        <a href="blog_list.html">主页</a>
        <a href="blog_edit.html">写博客</a>
        <a href="blog-login.html">登录</a>
    </div>
    <div class="sign_content">
    <div class="content">
        <div class="title">
            <h3>欢迎注册博客系统</h3>
        </div>
        <div class="row">
            <span>用户名  </span>
            <input type="text" id="username" >
        </div>
        <div class="row">
            <span>密码  </span>
            <input type="password" id="password">
        </div>
        <div class="row">
            <span>确认密码</span>
            <input type="password" id="password2" >
        </div>
        <div class="row">
            <button id="submit" onclick="mysub()">立即注册</button>
        </div>
    </div>
</div>
<script>
    function mysub(){
        //先拿到组件
        var username=jQuery("#username");
        var password=jQuery("#password");
        var password2=jQuery("#password2");
        //非空判断
        if(username.val().trim()==""){
          alert("请输入用户名");
          //光标跳转到用户名框
          username.focus();
          return false;
        }
        if(password.val()==""){
            alert("密码不能为空")
            password.focus();
          return false;
        }
        if(password.val()!=password2.val()){
            alert("两次输入密码不一致");
            password2.focus();
            return false;
        }
        //将提交按钮禁用
        jQuery("#submit").attr("disable","disable")
        //将前端数据传递到后端
        jQuery.ajax({
            url:"user/sign",
            type:"post",
            data:{
                "username":username.val().trim(),
                "password":password.val().trim()
            },
            success:function(res){
                if(res.code== 200 && res.data==1){
                    alert("注册成功");
                    location.href="blog-login.html";
                }else{
                    alert("注册失败"+ res.msg);
                    //取消禁用
                    jQuery("#submit").removeAttr("disable");
                }
            }

        });
    }

</script>
</body>

</html>